package com.p2l.letterblocks;

import android.app.Activity;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.view.View;
import android.widget.Button;

public class DialogRate extends Dialog {
	private SharedPreferences sp;
	private Activity activity;
	private Button rate, later;

	public DialogRate(Context context) {
		super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
		setContentView(R.layout.rate);
		
		activity = (Activity) context;
		sp = context.getSharedPreferences("LetterBlocks", Activity.MODE_PRIVATE);
		
		rate = (Button) findViewById(R.id.btnRate);
		rate.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Uri uri = Uri.parse("market://details?id=" + activity.getPackageName());
				Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
				try {
					Editor editor = sp.edit();
					editor.putBoolean("rated", true);
					editor.commit();
					activity.startActivity(goToMarket);
					dismiss();
				} catch (ActivityNotFoundException e) {
					//Toast.makeText(this, "Couldn't launch the market", Toast.LENGTH_LONG).show();
				}
			}
		});
		
		later = (Button) findViewById(R.id.btnLater);
		later.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
	}

}
